<?php
/*
 * 合作的列表页
 * @author     Mark <zhaody901@126.com>
 * @copyright  Copyright (c) 2013 lemon team
 * @version    $Id
 * @time       13-12-24 下午3:01
 */
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE.'/'.$module.'/common.inc.php';

ViewCheck::catExists() or Prompt::listNotFound();
ViewCheck::groupListPermission() or Prompt::noPermission();


$filter['catid']     =    getgpc('catid');
$filter['areaid']    =    getgpc('areaid');


$group=PCache::read("grouporder.php");//读取缓存会员组排序
if(!$group){
    Xd_save_groupcachefile();
}
/*

ViewCheck::catExists() or Prompt::listNotFound();
ViewCheck::groupListPermission() or Prompt::noPermission();
*/
// 增加url自动生成
/*
$buildBase = array('catid', 'areaid', 'typeid', 'order', 'kw', 'ctp', 'bid', 'mid', 'sid', 'page');
$buildPreserve = 'typeid';
$buildDrop = 'page,kw';
$selectedAttrs = array();
*/

if (!empty($CAT)) {
    unset($CAT['moduleid']);
    extract($CAT);
    //制作菜单列表
    // todo need CatList
    $maincat = Xd_get_catlist($CAT, $moduleid);
} else {
    $maincat[0] = get_maincat(0, $moduleid);
}

//$maincat = Search::mainCat(MODULE_NAME, $catid);



if (!empty($ARE)) {
    $mainarea=Xd_get_arealists($ARE);
} else {
    $mainarea[0] = get_mainarea(0);
}

$areaParentid = $ARE['parentid'];
if ($kw) {
    SearchCheck::length($kw);
    SearchCheck::timeLimit();
}

require_once DT_INC.'/post.func.php';
include load('search.lang');

// 地区搜索.
if ($areaid) {
    $condition .=  $ARE['child'] ? " AND areaid IN (".$ARE['arrchildid'].") " : " AND areaid=$areaid ";
}

if ($kw) {
    $condition .= " AND title LIKE '%$kw%'";
}
if (!empty($CAT)) {
    $condition .= ($CAT['child']) ? " AND catid IN (" . $CAT['arrchildid'] . ")" : " AND catid=$catid ";
}
if ($typeid != 99 && array_key_exists($typeid, $TYPES)) {
    $condition .= " AND typeid=$typeid ";
}
if($cityid&&$cityid!=0){
    $city_order='(case when areaid IN ('.$AREA[$cityid]["arrchildid"].') then 1 else 2 end ),';
	$push_city_order='(case when city like "%|'.$cityid.'|%" or city like "%|0|%" then 1 else 2 end ),';
}else{
    $city_order='';
}

$dorder  = array( $MOD['order'],/* $group['DESC'], $group['ASC'], */'addtime DESC'/*, 'addtime ASC'*/);
$order=isset( $order ) ? intval($order) : 0;
isset($order) && isset($dorder[$order]) or $order = 0;

$tags = array();//PPT
//if($DT_QST) {
if($kw) {
    if(strlen($kw) < $DT['min_kw'] || strlen($kw) > $DT['max_kw'])
    {
        Prompt::message(lang($L['word_limit'], array($DT['min_kw'], $DT['max_kw'])), getenv("HTTP_REFERER"));
    }
    if($DT['search_limit'] && $page == 1 && getenv("HTTP_REFERER")) {
        if(($DT_TIME - $DT['search_limit']) < Cookie::get('last_search')){
            Prompt::message(lang($L['time_limit'], array($DT['search_limit'])), getenv("HTTP_REFERER"));
            Cookie::set('last_search', $DT_TIME);
        }
    }
}
$fds = $MOD['fields'];
$condition = "(status=3 or status=2)";

if($keyword) $condition .= " AND keyword LIKE '%$keyword%'";
if (!empty($CAT)) {
    $condition .= ($CAT['child']) ? " AND catid IN (".$CAT['arrchildid'].")" : " AND {$table}.catid=$catid";
}
if($areaid) $condition .= ($ARE['child']) ? " AND areaid IN (".$ARE['arrchildid'].")" : " AND areaid=$areaid";

$items = $db->count($table, $condition, $DT['cache_search']);
$do = new CooperationModule($moduleid);
$tags=array();
if($items) {
    $tags=$do->getList($condition,$push_city_order.$dorder[$order],($DT['cache_search'] && $page == 1) ? 'CACHE' : '', $DT['cache_search']);
    if($page == 1 && $kw) keyword($kw, $items, $moduleid);

}

//是否在线
foreach($tags as $v=>$k ){
    $user = userinfo($k['username']);
    $online = online($user['userid']);
    $tags[$v]['tcompany']=$user['company'];
    $tags[$v]['online']=$online;
}

$showpage = 1;
$datetype = 5;
//over


$seo_file = 'list';
include DT_INC.'/seo.inc.php';

$template = $CAT['template'] ? $CAT['template'] : 'list';


include template($template, $module);

?>